package com.lxt.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lxt.common.HttpResult;
import com.lxt.pojo.Employee;
import com.lxt.pojo.VO.EmployeeVO;
import com.lxt.service.HrService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author kevin.lv
 * @date 2023/8/24 14:19
 */
@Api(value = "员工信息相关", tags = {"员工信息相关的api接口"})
@RestController
@RequestMapping("emp")
public class HrController extends BaseController {

    @Autowired
    private HrService hrService;


    @ApiOperation(value = "根据用户id查询用户信息", notes = "根据用户id查询用户信息", httpMethod = "POST")
    @PostMapping("/getEmpInfo")
    public HttpResult getEmpINfo(@RequestParam int empId) {
        Employee employee = hrService.queryEmployeeInfo(empId);
        return HttpResult.ok(employee);
    }


    @ApiOperation(value = "查询多个用户信息", notes = "查询多个用户信息", httpMethod = "POST")
    @PostMapping("/getListInfo")
    public HttpResult getEmpINfo(@RequestBody Employee employee) {
        List<Employee> employeeList = hrService.getListInfo(employee);
        return HttpResult.ok(employeeList);
    }

    @ApiOperation(value = "分页查询多个用户信息", notes = "分页查询多个用户信息", httpMethod = "POST")
    @PostMapping("/getPGListInfo")
    public HttpResult getPGListInfo(@RequestBody EmployeeVO employeeVO) {
        HttpResult httpResult = new HttpResult();
        PageHelper.startPage(employeeVO.getPageNum(), employeeVO.getPageSize());
        List<Employee> pgListInfo = hrService.getPGListInfo(employeeVO);
        PageInfo<Employee> pageInfo = new PageInfo<>(pgListInfo);
        httpResult.setData(pgListInfo);
        httpResult.setTotal(pageInfo.getTotal());
        return httpResult;
    }


    @ApiOperation(value = "新增用户", notes = "新增用户", httpMethod = "POST")
    @PostMapping("/addEmpInfo")
    public HttpResult addEmpINfo(@RequestBody Employee emp) {
        return HttpResult.ok(hrService.addEmployeeInfo(emp));
    }

    @ApiOperation(value = "更新用户信息", notes = "更新用户信息", httpMethod = "POST")
    @PostMapping("/updateEmpInfo")
    public HttpResult updateEmpINfo(@RequestBody Employee emp) {
        return HttpResult.ok(hrService.updateEmployeeInfo(emp));
    }

    @ApiOperation(value = "根据用户id删除用户信息", notes = "根据用户id删除用户信息", httpMethod = "POST")
    @PostMapping("/delEmpInfo")
    public HttpResult delEmpINfo(@RequestParam int empId) {
        return HttpResult.ok(hrService.delEmployeeInfo(empId));
    }


}
